<?php

/**
 *  @FileComment            [品牌管理后台控制器]
 *  @ProjectName             项目名称：shopFrame
 *  @FileName                   文件名称：BrandController.class.php
 *  @Author                       yuerengui <596580041@qq.com>
 *  @Date                          2014-10-10 11:51:34
 *  *
 */
class BrandController extends CommonController {

        private $model;

        public function __init() {
                parent::__init();
                $this->model = K('Brand');
        }

        public function index() {
                //显示所有品牌
                $data = $this->model->get_all();
                $this->assign('data', $data);
                $this->display();
        }

        public function add() {
                //添加品牌
                if (IS_POST) {
                        if ($this->model->create()) {
                                $this->model->add_logo();
                                $this->success('添加商品品牌成功！', U('index'));
                        } else {
                                $this->error($this->model->error);
                        }
                }
                $data = K('Type')->all();
                $this->assign('data', $data);
                $this->display();
        }

        public function del() {
                //删除品牌
                $bid = Q('get.bid', 0, 'intval');
                if ($this->model->del_data($bid)) {
                        $this->success('删除商品品牌成功！', U('index'));
                } else {
                        $this->error('删除商品品牌失败！', U('index'));
                }
        }

        public function edit() {
                //编辑品牌
                if (IS_POST) {
                        if ($this->model->create()) {
                                $bid = Q('post.bid', 0, 'intval');
                                $this->model->edit_logo($bid);
                                $this->success('修改商品品牌成功！', U('index'));
                        } else {
                                $this->error($this->model->error);
                        }
                }
                $Type = K('Type')->all();
                $this->assign('Type', $Type);
                $bid = Q('get.bid', 0, 'intval');
                $data = $this->model->get_one_data($bid);
                $logo = array(
                    0 => array(
                        'path' => $data['logo']
                    )
                );
                $this->assign('logo', $logo);
                $this->assign('data', $data);
                $this->display();
        }

        public function ajax_brand() {
                //异步选择类型的时候，将该类型下的所有品牌筛选出来
                $tid = Q('post.tid', 0, 'intval');
                $data = $this->model->get_data($tid);
                $this->ajax($data);
        }

}
